package com.fare.taluo.core.domain.queue.message.repository.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.dayatang.domain.QuerySettings;
import com.dayatang.hibernate.EntityRepositoryHibernate;
import com.fare.taluo.core.domain.queue.message.QueueEmailMessageEntity;
import com.fare.taluo.core.domain.queue.message.repository.QueueEmailMessageRepository;
import com.foreveross.threadpool.queue.WorkQueue;

@Repository
public class QueueEmailMessageRepositoryImpl extends EntityRepositoryHibernate
		implements QueueEmailMessageRepository{
	
	
	
	public List<QueueEmailMessageEntity> listPlanStartEntity(int maxSize){
//		super.find("from QueueEmailMessageEntity where planStartTime<=? and " +
//				" status=? order by createTime desc", new, QueueEmailMessageEntity.class)
//		return hibernateTemplate.getSessionFactory().
//			getCurrentSession().createCriteria(QueueEmailMessageEntity.class)
//			.add(Restrictions.lt("planStartTime", new Date()))
//			.add(Restrictions.eq("status", WorkQueue.STATUS_WAITING))
//			.addOrder(Order.asc("createTime")).setMaxResults(maxSize).list();
		//因表中有clob字段，而下面的查询会出现distinct，故取消，采用上面的查询方式
		return super.find(QuerySettings.create(QueueEmailMessageEntity.class).lt("planStartTime", new Date())
				.eq("status", WorkQueue.STATUS_WAITING).asc("createTime").setMaxResults(maxSize));
	}
	
	
}
